import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:provider/provider.dart';
import '../models/song.dart';
import '../providers/music_provider.dart';
import 'player_page.dart';
import 'music_player_page.dart';
import 'search_page.dart';
import 'notes_page.dart';
import 'profile_page.dart';
import '../utils/image_cache_service.dart';
import 'dart:math' as math;
import 'dart:io';

class MainPage extends StatefulWidget {
  const MainPage({super.key});

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> with TickerProviderStateMixin {
  int _currentIndex = 0;
  final ImageCacheService _imageCacheService = ImageCacheService();
  
  // 音乐封面旋转动画控制器
  late AnimationController _rotationController;
  late Animation<double> _rotationAnimation;

  @override
  void initState() {
    super.initState();
    
    // 初始化旋转动画
    _rotationController = AnimationController(
      duration: const Duration(seconds: 10), // 10秒旋转一圈
      vsync: this,
    );
    
    _rotationAnimation = Tween<double>(
      begin: 0.0,
      end: 1.0,
    ).animate(_rotationController);
  }

  @override
  void dispose() {
    _rotationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Consumer<MusicProvider>(
        builder: (context, musicProvider, child) {
          if (musicProvider.isLoading) {
            return const Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  CircularProgressIndicator(
                    color: Color(0xFFD33A4E),
                  ),
                  SizedBox(height: 16),
                  Text(
                    '正在加载音乐库...',
                    style: TextStyle(color: Colors.black54),
                  ),
                ],
              ),
            );
          }

          if (musicProvider.errorMessage.isNotEmpty) {
            return Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  const Icon(
                    Icons.error_outline,
                    size: 64,
                    color: Color(0xFFD33A4E),
                  ),
                  const SizedBox(height: 16),
                  Text(
                    musicProvider.errorMessage,
                    style: const TextStyle(color: Color(0xFFD33A4E)),
                    textAlign: TextAlign.center,
                  ),
                  const SizedBox(height: 16),
                  ElevatedButton(
                    onPressed: () {
                      musicProvider.loadMusicLibrary();
                    },
                    style: ElevatedButton.styleFrom(
                      backgroundColor: const Color(0xFFD33A4E),
                      foregroundColor: Colors.white,
                    ),
                    child: const Text('重试'),
                  ),
                ],
              ),
            );
          }

          return _buildMainContent(musicProvider);
        },
      ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
        backgroundColor: Colors.white,
        selectedItemColor: const Color(0xFFD33A4E),
        unselectedItemColor: Colors.grey,
        selectedLabelStyle: const TextStyle(fontSize: 10, fontWeight: FontWeight.w600),
        unselectedLabelStyle: const TextStyle(fontSize: 10),
        items: [
          const BottomNavigationBarItem(
            icon: Icon(Icons.music_note_outlined),
            activeIcon: Icon(Icons.music_note),
            label: '推荐',
          ),
          const BottomNavigationBarItem(
            icon: Icon(Icons.explore_outlined),
            activeIcon: Icon(Icons.explore),
            label: '发现',
          ),
          const BottomNavigationBarItem(
            icon: Icon(Icons.radio_outlined),
            activeIcon: Icon(Icons.radio),
            label: '漫游',
          ),
          const BottomNavigationBarItem(
            icon: Icon(Icons.chat_bubble_outline),
            activeIcon: Icon(Icons.chat_bubble),
            label: '笔记',
          ),
          const BottomNavigationBarItem(
            icon: Icon(Icons.person_outline),
            activeIcon: Icon(Icons.person),
            label: '我的',
          ),
        ],
      ),
    );
  }

  Widget _buildMainContent(MusicProvider musicProvider) {
    switch (_currentIndex) {
      case 0:
        return _buildRecommendPage(musicProvider);
      case 1:
        return _buildDiscoverPage();
      case 2:
        return _buildRoamingPage();
      case 3:
        return _buildNotesPage();
      case 4:
        return _buildProfilePage();
      default:
        return _buildRecommendPage(musicProvider);
    }
  }

  Widget _buildRecommendPage(MusicProvider musicProvider) {
    return Column(
      children: [
        Expanded(
          child: SingleChildScrollView(
            child: Column(
              children: [
                const SizedBox(height: 30),
                
                _buildSearchSection(),
                
                _buildGreetingSection(),
                
                _buildHorizontalCardsSection(),
                
                _buildRecommendSongsSection(musicProvider),
                
                _buildActivitySection(),
                
                const SizedBox(height: 100),
              ],
            ),
          ),
        ),
        
        if (musicProvider.currentSong != null)
          _buildMusicPlayerBar(musicProvider),
      ],
    );
  }

  Widget _buildSearchSection() {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
      child: Row(
        children: [
          Container(
            width: 36,
            height: 36,
            decoration: BoxDecoration(
              color: Colors.grey[100],
              shape: BoxShape.circle,
            ),
            child: const Icon(
              Icons.playlist_play,
              color: Colors.black54,
              size: 20,
            ),
          ),
          
          const SizedBox(width: 12),
          
          Expanded(
            child: Container(
              height: 36,
              decoration: BoxDecoration(
                color: const Color(0xFFE6E9EE),
                borderRadius: BorderRadius.circular(18),
            ),
            child: Row(
              children: [
                  const SizedBox(width: 12),
                  const Icon(
                    Icons.search,
                    color: Color(0xFFA5A6AE),
                    size: 20,
                  ),
                const SizedBox(width: 8),
                Expanded(
                    child: GestureDetector(
                      onTap: () {
                        Navigator.push(
                          context,
                          MaterialPageRoute(
                            builder: (context) => const SearchPage(),
                          ),
                        );
                      },
                      child: const Text(
                        '普通朋友',
                        style: TextStyle(
                          color: Colors.black87,
                          fontSize: 14,
                          fontWeight: FontWeight.w500,
                        ),
                      ),
                    ),
                  ),
                  const SizedBox(width: 8),
                  const Icon(
                    Icons.qr_code_scanner,
                    color: Color(0xFFA5A6AE),
                    size: 20,
                  ),
                  const SizedBox(width: 12),
                ],
              ),
            ),
          ),
          
          const SizedBox(width: 12),
          
          Container(
            width: 36,
            height: 36,
            decoration: BoxDecoration(
              color: Colors.grey[100],
              shape: BoxShape.circle,
            ),
            child: const Icon(
              Icons.mic,
              color: Colors.black54,
              size: 20,
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildGreetingSection() {
    return Container(
      width: double.infinity,
      margin: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
      child: Text(
        greeting,
        style: const TextStyle(
          fontSize: 24,
          fontWeight: FontWeight.w800,
          color: Colors.black,
        ),
      ),
    );
  }

  Widget _buildHorizontalCardsSection() {
    return Container(
      height: 190,
      margin: const EdgeInsets.symmetric(vertical: 10),
      child: ListView(
        scrollDirection: Axis.horizontal,
        padding: const EdgeInsets.symmetric(horizontal: 14),
        physics: const BouncingScrollPhysics(), // 添加弹性滚动效果
        children: [
          _buildCardWithImage(
            '每日推荐',
            '符合你口味的新鲜好歌',
            Icons.calendar_today,
            'img/推荐页/每日推荐.jpeg',
            () => _showDailyRecommend(),
          ),
          _buildCardWithImage(
            '心动模式',
            '红心歌曲相似推荐',
            Icons.favorite,
            'img/推荐页/心动模式.jpeg',
            () => _showHeartMode(),
          ),
          _buildCardWithImage(
            '新歌首发',
            '独创性的艺术',
            Icons.new_releases,
            'img/推荐页/新歌首发.jpeg',
            () => _showNewSongs(),
          ),
        ],
      ),
    );
  }

  Widget _buildCard(String title, String subtitle, IconData icon, Color color, VoidCallback onTap) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        width: 139,
        height: 190,
        margin: const EdgeInsets.only(right: 12),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(10),
          color: color,
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: const EdgeInsets.all(8.0),
            child: Row(
              children: [
                  Container(
                    width: 32,
                    height: 32,
                    decoration: BoxDecoration(
                      color: Colors.white.withOpacity(0.2),
                      borderRadius: BorderRadius.circular(8),
                    ),
                    child: Icon(icon, color: Colors.white, size: 20),
                  ),
                  const SizedBox(width: 8),
                  Expanded(
                    child: Text(
                      title,
                      style: const TextStyle(
                        fontSize: 18,
                        fontWeight: FontWeight.w800,
                        color: Colors.white,
                      ),
                    ),
                  ),
                ],
              ),
            ),
            const Spacer(),
            Container(
              width: double.infinity,
              padding: const EdgeInsets.all(10),
              decoration: BoxDecoration(
                color: Colors.black.withOpacity(0.2),
                borderRadius: const BorderRadius.only(
                  bottomLeft: Radius.circular(10),
                  bottomRight: Radius.circular(10),
                ),
              ),
              child: Text(
                subtitle,
                style: const TextStyle(
                  fontSize: 12,
                  fontWeight: FontWeight.w600,
                  color: Colors.white,
                ),
                textAlign: TextAlign.center,
                  ),
                ),
              ],
        ),
      ),
    );
  }

  Widget _buildCardWithImage(String title, String subtitle, IconData icon, String imagePath, VoidCallback onTap) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        width: 160, // 增加宽度以便更好地显示文本和滚动
        height: 190,
        margin: const EdgeInsets.only(right: 12),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(10),
          image: DecorationImage(
            image: AssetImage(imagePath),
            fit: BoxFit.cover,
          ),
        ),
        child: Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(10),
            gradient: LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              colors: [
                Colors.black.withOpacity(0.3),
                Colors.black.withOpacity(0.6),
              ],
            ),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Row(
                  children: [
                    Container(
                      width: 32,
                      height: 32,
                      decoration: BoxDecoration(
                        color: Colors.white.withOpacity(0.2),
                        borderRadius: BorderRadius.circular(8),
                      ),
                      child: Icon(icon, color: Colors.white, size: 20),
                    ),
                    const SizedBox(width: 8),
                    Expanded(
                      child: Text(
                        title,
                        style: const TextStyle(
                          fontSize: 18,
                          fontWeight: FontWeight.w800,
                          color: Colors.white,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              const Spacer(),
              Container(
                width: double.infinity,
                padding: const EdgeInsets.all(10),
                decoration: BoxDecoration(
                  color: Colors.black.withOpacity(0.4),
                  borderRadius: const BorderRadius.only(
                    bottomLeft: Radius.circular(10),
                    bottomRight: Radius.circular(10),
                  ),
                ),
                child: Text(
                  subtitle,
                  style: const TextStyle(
                    fontSize: 12,
                    fontWeight: FontWeight.w600,
                    color: Colors.white,
                  ),
                  textAlign: TextAlign.center,
                  maxLines: 1, // 限制为一行
                  overflow: TextOverflow.ellipsis, // 超出部分显示省略号
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildRecommendSongsSection(MusicProvider musicProvider) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 20),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text(
            '根据你喜爱的歌曲推荐',
            style: TextStyle(
              fontSize: 14,
              fontWeight: FontWeight.w600,
              color: Colors.black87,
            ),
          ),
          const SizedBox(height: 15),
          if (musicProvider.isLoading)
            const Center(
              child: Padding(
                padding: EdgeInsets.all(32),
                child: Column(
                  children: [
                    CircularProgressIndicator(color: Color(0xFFD33A4E)),
                    SizedBox(height: 16),
                    Text('正在扫描音乐库...', style: TextStyle(color: Colors.grey)),
                  ],
                ),
              ),
            )
          else if (musicProvider.allSongs.isEmpty)
        Container(
          width: double.infinity,
              padding: const EdgeInsets.all(32),
              decoration: BoxDecoration(
                color: Colors.grey[50],
                borderRadius: BorderRadius.circular(12),
              ),
              child: Column(
                children: [
                  Icon(
                    Icons.music_off,
                    size: 48,
                    color: Colors.grey[400],
                  ),
                  const SizedBox(height: 16),
                  Text(
                    '未找到本地音乐',
                    style: TextStyle(
                      fontSize: 16,
                      color: Colors.grey[600],
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  const SizedBox(height: 8),
                  Text(
                    '请确保设备中有音频文件',
                    style: TextStyle(
                      fontSize: 14,
                      color: Colors.grey[500],
                    ),
                  ),
                  const SizedBox(height: 16),
                  ElevatedButton.icon(
                    onPressed: () => musicProvider.refreshMusicLibrary(),
                    icon: const Icon(Icons.refresh),
                    label: const Text('重新扫描'),
                    style: ElevatedButton.styleFrom(
                      backgroundColor: const Color(0xFFD33A4E),
                      foregroundColor: Colors.white,
                    ),
                  ),
                ],
              ),
            )
          else
            SizedBox(
              height: 155,
              child: ListView.builder(
                scrollDirection: Axis.horizontal,
                itemCount: (musicProvider.allSongs.length / 3).ceil(),
                itemBuilder: (context, groupIndex) {
                  return Container(
                    width: 305,
                    margin: const EdgeInsets.only(right: 17),
                    child: _buildSongGroup(musicProvider, groupIndex),
                  );
                },
              ),
            ),
        ],
      ),
    );
  }

  Widget _buildSongGroup(MusicProvider musicProvider, int groupIndex) {
    final startIndex = groupIndex * 3;
    final endIndex = math.min(startIndex + 3, musicProvider.allSongs.length);
    final groupSongs = musicProvider.allSongs.sublist(startIndex, endIndex);

    return Column(
      children: List.generate(groupSongs.length, (index) {
        final song = groupSongs[index];
        final isCurrentSong = musicProvider.currentSong?.id == song.id;
        
        return Container(
          height: 45,
          margin: EdgeInsets.only(top: index == 0 ? 0 : 10),
          child: _buildSongItemInGroup(song, isCurrentSong, musicProvider),
        );
      }),
    );
  }

  Widget _buildSongItemInGroup(Song song, bool isCurrentSong, MusicProvider musicProvider) {
    return Row(
      children: [
        // 左侧可点击区域（封面、歌曲信息、喜欢按钮）
        Expanded(
          child: GestureDetector(
            onTap: () {
              print('推荐歌曲被点击: ${song.name} - ${song.artist}');
              // 先设置当前歌曲然后跳转
              musicProvider.playSong(song);
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => const MusicPlayerPage(),
                ),
              );
            },
            child: Container(
              color: Colors.transparent, // 确保整个区域都可以点击
              child: Row(
              children: [
                Container(
                  width: 42,
                  height: 42,
                  margin: const EdgeInsets.only(left: 7, top: 2),
                  decoration: BoxDecoration(
                    color: isCurrentSong 
                        ? const Color(0xFFD33A4E).withOpacity(0.2)
                        : Colors.grey[200],
                    borderRadius: BorderRadius.circular(6),
                    image: _getAlbumArtDecoration(song.albumArtUri),
                  ),
                  child: song.albumArtUri == null || song.albumArtUri!.isEmpty
                      ? Icon(
                          isCurrentSong ? Icons.music_note : Icons.music_note_outlined,
                          color: isCurrentSong 
                              ? const Color(0xFFD33A4E) 
                              : Colors.grey[500],
                          size: 20,
                        )
                      : null,
                ),
                
                const SizedBox(width: 13),
                
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        song.name,
                        style: TextStyle(
                          fontSize: 14,
                          fontWeight: FontWeight.w800,
                          color: isCurrentSong 
                              ? const Color(0xFFD33A4E) 
                              : const Color(0xFF3D3D3D),
                        ),
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                      ),
                      const SizedBox(height: 2),
                      Text(
                        song.artist,
                        style: const TextStyle(
                          fontSize: 10,
                          fontWeight: FontWeight.w800,
                          color: Color(0xFFA6A6A6),
                        ),
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ],
                  ),
                ),
                
                Container(
                  width: 12,
                  height: 12,
                  margin: const EdgeInsets.only(right: 8, top: 17),
                  child: const Icon(
                    Icons.favorite,
                    color: Color(0xFFFF0707),
                    size: 12,
                  ),
                ),
              ],
              ),
            ),
          ),
        ),
        
        // 播放按钮（只播放，不跳转）
        GestureDetector(
          onTap: () {
            print('播放按钮被点击: ${song.name}');
            musicProvider.playSong(song);
          },
          child: Container(
            width: 30,
            height: 30,
            margin: const EdgeInsets.only(right: 5, top: 8),
            decoration: BoxDecoration(
              color: Colors.grey[100],
              borderRadius: BorderRadius.circular(15),
            ),
            child: const Icon(
              Icons.play_arrow,
              color: Colors.black87,
              size: 20,
            ),
          ),
        ),
      ],
    );
  }

  Widget _buildActivitySection() {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 20),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text(
            '邀你一起，为喜爱的歌曲加分',
            style: TextStyle(
              fontSize: 14,
              fontWeight: FontWeight.w600,
              color: Colors.black87,
            ),
          ),
          const SizedBox(height: 15),
          Container(
            width: double.infinity,
            height: 148,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(10),
              image: const DecorationImage(
                image: AssetImage('img/推荐页/活动图片.jpeg'),
                fit: BoxFit.cover,
              ),
            ),
            child: Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10),
                gradient: LinearGradient(
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter,
                  colors: [
                    Colors.black.withOpacity(0.3),
                    Colors.black.withOpacity(0.6),
                  ],
                ),
              ),
              child: const Center(
                child: Text(
                  '🎵 音乐活动推广 🎵',
                  style: TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                    color: Colors.white,
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildMusicPlayerBar(MusicProvider musicProvider) {
    final song = musicProvider.currentSong!;
    
    // 根据播放状态控制旋转动画
    if (musicProvider.isPlaying) {
      _rotationController.repeat();
    } else {
      _rotationController.stop();
    }
    
    return Container(
      height: 55,
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
          top: BorderSide(
            color: Colors.grey[200]!,
            width: 0.5,
          ),
        ),
      ),
      child: Row(
        children: [
          // 左侧可点击区域（封面和歌曲信息）
          Expanded(
            child: GestureDetector(
              onTap: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => const MusicPlayerPage(),
                  ),
                );
              },
              child: Row(
                children: [
                  const SizedBox(width: 17),
                  
                  Container(
                    width: 45,
                    height: 45,
                    decoration: const BoxDecoration(
                      color: Colors.black,
                      shape: BoxShape.circle,
                    ),
                    child: RotationTransition(
                      turns: _rotationAnimation,
                      child: Container(
                        margin: const EdgeInsets.all(5),
                        decoration: BoxDecoration(
                          color: Colors.grey[300],
                          shape: BoxShape.circle,
                          image: _getAlbumArtDecoration(song.albumArtUri),
                        ),
                        child: song.albumArtUri == null || song.albumArtUri!.isEmpty
                            ? const Icon(
                                Icons.music_note,
                                color: Colors.grey,
                                size: 20,
                              )
                            : null,
                      ),
                    ),
                  ),
                  
                  const SizedBox(width: 12),
                  
                  Expanded(
                    child: Text(
                      song.name,
                      style: const TextStyle(
                        color: Colors.black87,
                        fontSize: 16,
                        fontWeight: FontWeight.w500,
                      ),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ),
                ],
              ),
            ),
          ),
          
          // 播放按钮（不跳转页面）
          GestureDetector(
            onTap: musicProvider.togglePlayPause,
            child: Container(
              width: 36,
              height: 36,
              margin: const EdgeInsets.only(right: 8),
              child: Icon(
                musicProvider.isPlaying ? Icons.pause_circle_filled : Icons.play_circle_filled,
                color: Colors.black54,
                size: 36,
              ),
            ),
          ),
          
          // 菜单按钮（跳转到音乐播放页）
          GestureDetector(
            onTap: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => const MusicPlayerPage(),
                ),
              );
            },
            child: Container(
              width: 36,
              height: 36,
              margin: const EdgeInsets.only(right: 12),
              child: const Icon(
                Icons.menu,
                color: Colors.black54,
                size: 24,
              ),
            ),
          ),
      ],
      ),
    );
  }

  Widget _buildDiscoverPage() {
    return const Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Icon(Icons.explore, size: 64, color: Colors.grey),
          SizedBox(height: 16),
          Text('发现页面', style: TextStyle(color: Colors.black54)),
          Text('即将推出...', style: TextStyle(color: Colors.grey)),
        ],
      ),
    );
  }

  Widget _buildRoamingPage() {
    return const Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Icon(Icons.radio, size: 64, color: Colors.grey),
          SizedBox(height: 16),
          Text('漫游页面', style: TextStyle(color: Colors.black54)),
          Text('即将推出...', style: TextStyle(color: Colors.grey)),
        ],
      ),
    );
  }

  Widget _buildNotesPage() {
    return const NotesPage();
  }

  Widget _buildProfilePage() {
    return Consumer<MusicProvider>(
      builder: (context, musicProvider, child) {
        return Column(
          children: [
            const Expanded(
              child: ProfilePage(),
            ),
            
            if (musicProvider.currentSong != null)
              _buildMusicPlayerBar(musicProvider),
          ],
        );
      },
    );
  }

  void _showDailyRecommend() {
                ScaffoldMessenger.of(context).showSnackBar(
      const SnackBar(
        content: Text('每日推荐功能开发中...'),
        duration: Duration(seconds: 1),
      ),
    );
  }

  void _showHeartMode() {
        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(
        content: Text('心动模式功能开发中...'),
        duration: Duration(seconds: 1),
          ),
        );
      }

  void _showNewSongs() {
    ScaffoldMessenger.of(context).showSnackBar(
      const SnackBar(
        content: Text('新歌首发功能开发中...'),
        duration: Duration(seconds: 1),
      ),
    );
  }

  String get greeting {
    final hour = DateTime.now().hour;
    if (hour < 12) {
      return '早上好';
    } else if (hour < 18) {
      return '下午好';
    } else {
      return '晚上好';
    }
  }

  /// 获取专辑封面装饰，使用缓存避免闪烁
  DecorationImage? _getAlbumArtDecoration(String? albumArtUri) {
    final imageProvider = _imageCacheService.getImageProvider(albumArtUri);
    if (imageProvider != null) {
      return DecorationImage(
        image: imageProvider,
        fit: BoxFit.cover,
      );
    }
    return null;
  }
} 